﻿using System;

namespace OS.Common.Extention
{
    /// <summary>
    /// URL扩展方法类
    /// </summary>
    public static class UrlExtension
    {
        /// <summary>
        /// Url编码处理
        /// </summary>
        /// <param name="input">输入字符串</param>
        /// <returns></returns>
        public static string UrlEncode(this string input)
        {
            return !string.IsNullOrEmpty(input) ? Uri.EscapeDataString(input) : string.Empty;
        }

        /// <summary>
        /// Url编码处理
        /// </summary>
        public static string UrlEncode(this object input)
        {
            return input != null ? Uri.EscapeDataString(input.ToString()) : string.Empty;
        }

        /// <summary>
        /// Url解码处理
        /// </summary>
        public static string UrlDecode(this string input)
        {
            return !string.IsNullOrEmpty(input) ? Uri.UnescapeDataString(input) : string.Empty;
        }
    }
}